package com.xiu.java8.lambda;

public class LambdaTtest {
	
	  static String salutation = "Hello! ";
	
	public static void main(String[] args) {
		LambdaTtest lambdaTtest = new LambdaTtest();
		// 类型声明
		MathOperation addition = (int a, int b) -> a + b;
		// 不用类型声明
		MathOperation subtraction = (a, b) -> a - b;
		// 大括号中的返回语句
		MathOperation multiplication = (int a, int b) -> {return a * b;};
		// 没有大括号及返回语句
		MathOperation division = (int a, int b) -> a / b;
		System.out.println("10 + 5 = " + lambdaTtest.operate(10, 5, addition));
		System.out.println("10 + 5 = " + lambdaTtest.operate(10, 5, (a, b) -> a + b));
		System.out.println("10 - 5 = " + lambdaTtest.operate(10, 5, subtraction));
		System.out.println("10 x 5 = " + lambdaTtest.operate(10, 5, multiplication));
		System.out.println("10 / 5 = " + lambdaTtest.operate(10, 5, division));
		GreetingService greetService1 =message->System.out.println("hello "+message);
		GreetingService greetService2 =(message)->System.out.println("hello "+message);
		greetService1.sayMessage("Runoob");
		greetService2.sayMessage("Google");
		GreetingService greetService3 = message -> System.out.println(salutation + message);
//		salutation="";
	    greetService3.sayMessage("Runoob");
	    int num = 1;
	    Converter converter=(param)->System.out.println(String.valueOf(param+num));
	    converter.convert(2);
//	    num=3;
	}

	private int operate(int a, int b, MathOperation mathOperation) {
		return mathOperation.operation(a, b);
	}

}

interface MathOperation {
	int operation(int a, int b);
}

interface GreetingService {
	void sayMessage(String message);
}

interface Converter<T1, T2> {
    void convert(int i);
}
